package com.ponchware.classes
{
	import flash.net.SharedObject;
	
	/** Holds the global settings of the user along with default values **/
	public class Settings
	{
		public static const BACKGROUND_MUSIC:Array = [{label: "Countdown to Chaos", filename: "Countdown to Chaos.mp3"},
														{label: "Doctor Dred", filename: "Doctor Dred.mp3"},
														{label: "Race Against Time Warp", filename: "Race Against Time Warp.mp3"}];
		public static const MUSIC_CHAOS:Number = 0;
		public static const MUSIC_DRED:Number = 1;
		public static const MUSIC_RACE:Number = 2;
		
		private static var settings_so:SharedObject;
		
		[Bindable]
		public static var backgroundMusicEnabled:Boolean = true;
		[Bindable]
		public static var backgroundMusicIndex:Number = MUSIC_DRED;
		[Bindable] 
		public static var soundEffectsEnabled:Boolean = true;
		[Bindable]
		public static var frameRate:Number = 60;
		
		public function Settings()
		{
		}

		public static function load():void
		{
			settings_so = SharedObject.getLocal("settings", "/", false);
			for (var prop:String in settings_so.data)
			{
				var val:* = settings_so.data[prop];
				//trace("SO Prop " + prop + " = " + val);
				
				switch (prop)
				{
					case "backgroundMusicEnabled":
						backgroundMusicEnabled = val;
						break;
					case "backgroundMusicIndex":
						backgroundMusicIndex = val;
						break;
					case "soundEffectsEnabled":
						soundEffectsEnabled = val;
						break;
					case "frameRate":
						frameRate = val;
						break;
					default:
						trace("ERROR, unknown property");
						break;
				}
			} 
		}
		
		public static function save():void
		{
			settings_so.setProperty("backgroundMusicEnabled", backgroundMusicEnabled);
			settings_so.setProperty("backgroundMusicIndex", backgroundMusicIndex);
			settings_so.setProperty("soundEffectsEnabled", soundEffectsEnabled);
			settings_so.setProperty("frameRate", frameRate);
			settings_so.flush();
		}
	}
}